require "test/unit"

def rand_array(max_len=16, min_len=1, max_val=256)
    len = min_len + (rand * (max_len - min_len + 1)).to_i
    values = []
    len.times{ values << (max_val * rand).to_i }
    values
end

# pass block with order validation function {|val_l, val_r|}
def assert_ordered(array)
  # H2 simplest way to iterate an array excluding the last value
  (0..array.length - 2).each do |i|
    val_l = array[i]
    val_r = array[i + 1]
    
    is_ordered = yield(val_l, val_r)
    assert(is_ordered)
  end
  
  def assert_arrays_equal(arr0, arr1, do_sort=true)
    arr0.sort! and arr1.sort! if do_sort    # funny
    
    assert_equal arr0.size, arr1.size
    
    for i in 0...arr0.size
      assert_equal arr0[i], arr1[i]
    end
  end
end